HA$PBExportHeader$u_cst_manto_main_fichas.sru
forward
global type u_cst_manto_main_fichas from u_cst_tabpage
end type
type uo_tab from u_cst_tabcontrol within u_cst_manto_main_fichas
end type
type uo_toolbarstrip from u_cst_toolbarstrip within u_cst_manto_main_fichas
end type
end forward

global type u_cst_manto_main_fichas from u_cst_tabpage
integer width = 3090
integer height = 2140
event ue_mostrar ( powerobject ap_object,  boolean ab_tab )
event ue_grabar ( )
event type integer ue_validar ( )
event type long ue_getdwmodified ( )
uo_tab uo_tab
uo_toolbarstrip uo_toolbarstrip
end type
global u_cst_manto_main_fichas u_cst_manto_main_fichas

type variables
s_parm istr_parm
boolean dw_has_focus
string is_error  ,is_button,is_tabla ,is_idcodigo,is_menu
long il_id 
integer ii_currentrow
datastore ids_datastore
Window iw_parent
u_cst_powerdock uo_powerdock
userobject iuo_tab
u_cst_mle uo_mle_1


userobject iuo_user[]
end variables

forward prototypes
public function integer of_getwindow ()
end prototypes

event ue_mostrar(powerobject ap_object, boolean ab_tab);INTEGER li_tab

string ls_dw,ls_button,ls_entidad
long ll_codigo,ll_Rows

istr_parm        = ap_object

ids_datastore   = istr_parm.ads_menu //aqui recupera el datastore
uo_powerdock = istr_parm.auo_powerdock 
is_button         = istr_parm.as_button
//ls_dw              = ids_datastore.object.tDw1[1]
is_tabla           = ids_datastore.object.tTabla[1]
iuo_tab            = istr_parm.auo_userobject
uo_powerdock.of_setdocumenttext( iuo_tab ,is_button+'/ '+ is_tabla)


choose case upper(is_button)
	case 'NUEVO'
		uo_toolbarstrip.of_setenabled( 'Grabar', true)		
		uo_toolbarstrip.of_setenabled( 'Cancelar', true)
	CASE 'EDITAR'
		uo_toolbarstrip.of_setenabled( 'Grabar', true)		
		uo_toolbarstrip.of_setenabled( 'Cancelar', TRUE)
	CASE 'CONSULTAR'
		uo_toolbarstrip.of_setenabled( 'Grabar', false)
		uo_toolbarstrip.of_setenabled( 'Cancelar', false)
END CHOOSE

FOR li_tab = 1 TO uo_tab.of_gettabcount( )
	iuo_user[li_tab].DYNAMIC EVENT ue_mostrar(ap_object,ab_tab)
NEXT
IF  uo_tab.of_gettabcount( ) > 0  THEN 	UO_TAB.of_selecttab(iuo_user[1])


end event

event ue_grabar();

 
 
 iuo_user[1].DYNAMIC EVENT UE_gRABAR()
 
//integer li_return=1
//if dw_1.accepttext( ) = -1 Then Return // -1
////If f_findrequired(dw_1) = -1 Then Return 
//
//if dw_1.update(true,false) = 1 then
//	dw_1.resetupdate()
//	commit;
//	
//	f_msj('Guardado satisfactoriamente',4)
//else
//	//dw_1.resetupdate()
//	rollback ;
//	f_msj('Error',1)
//	return 
//end if
//
//uo_powerdock.of_setdocumenttext( iuo_tab ,'Consultar / '+is_tabla)
//dw_1.enabled= false
//uo_toolbarstrip.of_setenabled( 'Grabar', false)
//uo_toolbarstrip.of_setenabled( 'Cancelar', false)
end event

event type integer ue_validar();return 0
end event

event type long ue_getdwmodified();long ll_dwmodified
integer li_dw
ll_dwmodified = 0
for li_dw = 1 to UpperBound(iuo_user[])
	ll_dwmodified =ll_dwmodified +  iuo_user[li_dw ].EVENT DYNAMIC ue_getdwmodified()
	
next

return ll_dwmodified
end event

public function integer of_getwindow (); PowerObject	lpo_parent
Window lw_window

// loop thru parents until a window is found
lpo_parent = GetParent()
Do While lpo_parent.TypeOf() <> Window! and IsValid(lpo_parent)
	lpo_parent = lpo_parent.GetParent()
Loop

// set return to the window or null if not found
If IsValid (lpo_parent) Then
	lw_window = lpo_parent
Else
	SetNull(lw_window)
End If

iw_parent = lw_window

RETURN 1
end function

on u_cst_manto_main_fichas.create
int iCurrent
call super::create
this.uo_tab=create uo_tab
this.uo_toolbarstrip=create uo_toolbarstrip
iCurrent=UpperBound(this.Control)
this.Control[iCurrent+1]=this.uo_tab
this.Control[iCurrent+2]=this.uo_toolbarstrip
end on

on u_cst_manto_main_fichas.destroy
call super::destroy
destroy(this.uo_tab)
destroy(this.uo_toolbarstrip)
end on

event constructor;call super::constructor;string ls_dw3,ls_dw2,ls_opc,ls_dw,ls_user, ls_entidad,ls_menu
long ll_codigo,ll_Rows

of_getwindow()
istr_parm        = message.powerobjectparm
ids_datastore   = istr_parm.ads_menu //aqui recupera el datastore
uo_powerdock = istr_parm.auo_powerdock 
is_button        = istr_parm.as_button
ls_dw              = ids_datastore.object.tDw1[1]
is_tabla           = ids_datastore.object.tTabla[1]
iuo_tab            = istr_parm.auo_userobject
is_menu =        ids_datastore.object.idMenu[1]


//EVENT ue_mostrar (istr_parm,true)

end event

event resize;call super::resize;uo_toolbarstrip.Width =(this.width - 12) 
uo_tab.Resize(Width, Height  )
end event

event ue_postconstructor;call super::ue_postconstructor;integer li_tab_count,li_tab
string ls_ficha,ls_uo,ls_img
long ll_image

datastore lds_menuficha

lds_menuficha = Create DataStore
lds_menuficha.DataObject ='d_mmenuficha_idmenu'// "d_mainmenu"
lds_menuficha.settransobject( sqlca)
lds_menuficha.retrieve(is_menu)

for li_tab = 1 to lds_menuficha.rowcount()
	//uo_tab.of_OpenTab(uo_mle_1, 'Usuarios',1)	
	ls_ficha = lds_menuficha.object.tdesc[li_tab]
	ls_uo = lds_menuficha.object.tUserObject[li_tab]
	ls_img = lds_menuficha.object.timg[li_tab]
	
	istr_parm.ads_menuficha  = lds_menuficha
	istr_parm.as_string1 =lds_menuficha.object.tdw1[li_tab]
	
	uo_tab.of_opentab( iuo_user[li_tab],istr_parm, ls_ficha ,ls_img,ls_uo)
     uo_tab.of_SetStyle(uo_tab.VS2005)
	uo_tab.of_hideclosebutton( )
//	uo_tab.of_showarrows( )
	//uo_tab.of_showchevron( )
next

if lds_menuficha.rowcount() > 0  then  uo_tab.of_selecttab(iuo_user[1])

choose case upper(is_button)
	case 'NUEVO'
		  uo_toolbarstrip.of_setenabled( 'Grabar', true)	
		  uo_toolbarstrip.of_setenabled( 'Cancelar', true)
//		  dw_1.setcolumn( 4)
//		  dw_1.setfocus( )
		 
	case 'EDITAR'
		 uo_toolbarstrip.of_setenabled( 'Grabar', true)	
		 uo_toolbarstrip.of_setenabled( 'Cancelar', true)
//		 dw_1.setcolumn( 4)
//		 dw_1.setfocus( )
 case 'CONSULTAR'
		 uo_toolbarstrip.of_setenabled( 'Grabar', FALSE)		
		uo_toolbarstrip.of_setenabled( 'Cancelar', false)
End choose 
end event

type uo_tab from u_cst_tabcontrol within u_cst_manto_main_fichas
integer y = 112
integer width = 3077
integer height = 2016
integer taborder = 30
end type

on uo_tab.destroy
call u_cst_tabcontrol::destroy
end on

type uo_toolbarstrip from u_cst_toolbarstrip within u_cst_manto_main_fichas
integer y = 4
integer width = 3067
integer taborder = 20
end type

on uo_toolbarstrip.destroy
call u_cst_toolbarstrip::destroy
end on

event ue_buttonclicked;call super::ue_buttonclicked;integer li_tab,li_cont,li_ok
choose case upper(as_button)
	case 'GRABAR'
		//EVENT UE_grabar( )
		li_cont = 0
		for li_tab = 1 to uo_tab.of_gettabcount( )
			li_ok = iuo_user[li_tab].DYNAMIC EVENT ue_grabar()
			li_cont  = li_cont + li_ok
		NExt
//		for li_tab = 1 to uo_tab.of_gettabcount( )
		if	 li_cont = uo_tab.of_gettabcount( ) then
			commit;
			f_msj('Guardado satisfactoriamente',4)
		else
			ROLLBACK;
			f_msj('ERROR',4)
		end if
//				iuo_user[li_tab].DYNAMIC EVENT ue_conforme() ue_conforme
//			else
//				iuo_user[li_tab].DYNAMIC EVENT ue_rollback()
//			end if
//		next
	
	
	case 'CANCELAR'
		IF UPPER(is_button) = 'EDITAR' THEN
			uo_powerdock.of_setdocumenttext( iuo_tab ,'Consultar / '+is_tabla)
			//dw_1.enabled= false
			uo_toolbarstrip.of_setenabled( 'Grabar', false)
			uo_toolbarstrip.of_setenabled( 'Cancelar', false)
		ELSE
//			dw_1.reset()
//		    dw_1.insertrow( 0)
		END IF

	case 'SALIR'
		   uo_powerdock.of_closedocument(uo_powerdock.of_getactiveobject( ))
END CHOOSE
end event

event constructor;call super::constructor;this.of_AddItem('Grabar', 'Save!')
this.of_setenabled('Grabar', false)

this.of_AddItem('Cancelar', 'Undo!')
//this.of_AddItem('Salir', 'Exit!')
this.of_DisplayText(true)


end event

